#include "threadPool.h"
int recvn(int netfd, void *buf, int length)
{
	int total = 0; // 存储已经读取了多少个字节
	int ret;
	char *p = (char *)buf; // 一个char一个字节
	while (total < length)
	{
		ret = recv(netfd, p + total, length - total, 0);
		total += ret;
	}
}
int sendn(int fd_send, char *send_buf, int len)
{
	int sum = 0;
	int nsend;
	while (sum < len)
	{
		nsend = send(fd_send, send_buf + sum, len - sum, 0);
		sum += nsend;
	}
	return sum;
}
void get_salt(char *salt, char *passwd)
{
	int i, j;
	// 取出salt,i记录密码字符下标,j记录$出现次数
	for (i = 0, j = 0; passwd[i] && j != 3; ++i)
	{
		if (passwd[i] == '$')
			++j;
	}
	strncpy(salt, passwd, i - 1);
}
int md5(char *str,unsigned char *md){
    int fd = open(str, O_RDWR);
    MD5_CTX c;
    MD5_Init(&c);
    char buf[4096];
    while(1){
        bzero(buf,4096);
        ssize_t ret = read(fd,buf,4096);
        if(ret == 0){
            break;
        }
        MD5_Update(&c,buf,ret);
    }
    unsigned char MD[16]={0};
    MD5_Final(MD,&c);
	memcpy(md, MD, sizeof(MD));
    for(int i = 0; i < 16;++i){
        printf("%02x", MD[i]);
    }
    printf("\n");
	return 0;
}